const { Sequelize } = require('sequelize')
const { sqlLogger } = require('./log4js')
require('dotenv').config()

// 判断当前环境
const mysqlConfig = {
  host: 'bj-cdb-49czgo4s.sql.tencentcdb.com',
  port: 23797,
  timezone: '+08:00', // 强制 UTC
  dialect: 'mysql',
  logging: (sql) => {
    return sqlLogger.debug(sql)
  },
}
const sequelize = new Sequelize('blog', 'root', 'Mxj12345++', mysqlConfig)
try {
  sequelize.authenticate().then(() => {
    console.log('连接到MySQL服务器...')
  })
} catch (error) {
  console.error('无法连接到数据库:', error)
}
module.exports = sequelize
